package com.icss.train_sys_back.controller.admin.ticket_manage;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.icss.train_sys_back.entity.ResponseResult;
import com.icss.train_sys_back.entity.ticket_manage.ChangeTicketEntity;
import com.icss.train_sys_back.entity.ticket_manage.RefundTicketEntity;
import com.icss.train_sys_back.service.ticket_manage.ChangeTicketService;
import com.icss.train_sys_back.service.ticket_manage.Impl.ChangeTicketServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 小泽
 * @createTime 2025/10/7 18:28
 */
@RestController
@RequestMapping("/admin/change_manage")
@Slf4j
public class ChangeTicketController {
    @Autowired
    private ChangeTicketService changeTicketService;

    //改签记录分页+条件查询
    @GetMapping("/getList")
    public ResponseResult getListConditions(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "8") Integer pageSize,
            @RequestParam(required = false) String changeId,
            @RequestParam(required = false) String orderId,
            @RequestParam(required = false) String username,
            @RequestParam(required = false) Integer status
    ) {
        log.info("改签记录分页+条件查询 page = {} pageSize = {} refundId = {} orderId = {}  username ={} status={} ",
                page, pageSize, changeId, orderId, username, status);
        PageHelper.startPage(page, pageSize);
        List<ChangeTicketEntity> changeTicketEntityList = changeTicketService.getListConditions(changeId, orderId, username, status);
        PageInfo<ChangeTicketEntity> pageInfo = new PageInfo<>(changeTicketEntityList);
        return ResponseResult.success(pageInfo);
    }

    //改签审核通过处理
    @PostMapping("/approve/{changeId}")
    public ResponseResult approve(@PathVariable("changeId") String changeId) {
        log.info("审核通过，changeId = {}", changeId);
        Integer updateStatus = 1;
        changeTicketService.updateStatus(changeId, updateStatus);
        return ResponseResult.success();
    }

    //改签审核拒绝退票处理
    @PostMapping("/reject")
    public ResponseResult reject(@RequestBody ChangeTicketEntity changeTicket) {
        log.info("改签审核拒绝退票处理 refundRecord = {}", changeTicket);
        changeTicketService.updateStatusReject(changeTicket.getChangeId(),changeTicket.getRemark());
        return ResponseResult.success();
    }
}
